//
//  WSButton.m
//  WSBaseKit
//
//  Created by zhangcong on 2020/8/18.
//  Copyright © 2020 zhangcong. All rights reserved.
//

#import "WSButton.h"
#import "WSConst.h"

@implementation WSButton


- (void)setFrame:(CGRect)frame {
    [super setFrame:frame];
    self.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    [[self imageView] setContentMode:UIViewContentModeScaleAspectFill];
}

- (CGRect)imageRectForContentRect:(CGRect)contentRect {
    self.clipsToBounds = YES;
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = CGRectGetWidth(self.bounds)/2;
//    self.layer.shouldRasterize = YES;
    return self.bounds;
}

@end

@implementation FullTextButton

- (CGRect)titleRectForContentRect:(CGRect)contentRect {
    return self.bounds;
}

@end

@implementation FullButton

- (void)setFrame:(CGRect)frame {
    [super setFrame:frame];
    self.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    [[self imageView] setContentMode:UIViewContentModeScaleAspectFill];
    
    
}
- (CGRect)imageRectForContentRect:(CGRect)contentRect {
    return self.bounds;
}
- (void)cornerRadiusSetting:(CGFloat)radius {
    
    self.clipsToBounds = YES;
    self.layer.cornerRadius = radius;
    self.layer.shouldRasterize = YES;
}

@end




@implementation BXButton

- (void)setFrame:(CGRect)frame {
    [super setFrame:frame];
    self.contentEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    [[self imageView] setContentMode:UIViewContentModeScaleAspectFill];
}
- (CGRect)imageRectForContentRect:(CGRect)contentRect {
    return self.bounds;
}
- (void)cornerRadiusSetting:(CGFloat)radius {
    self.clipsToBounds = YES;
    self.layer.cornerRadius = radius;
}
@end



@implementation ExtendTouchAreaButton

- (BOOL)pointInside:(CGPoint)point withEvent:(nullable UIEvent *)event {
    return CGRectContainsPoint(HitTestingBounds(self.bounds, self.extendedWidth, self.extendedHeight), point);
}

CGRect HitTestingBounds(CGRect bounds, CGFloat extendedWidth, CGFloat extendedHeight) {
    CGRect hitTestingBounds = bounds;
    if (extendedWidth > bounds.size.width) {
        hitTestingBounds.size.width = extendedWidth;
        hitTestingBounds.origin.x -= (hitTestingBounds.size.width - bounds.size.width)/2;
    }
    if (extendedHeight > bounds.size.height) {
        hitTestingBounds.size.height = extendedHeight;
        hitTestingBounds.origin.y -= (hitTestingBounds.size.height - bounds.size.height)/2;
    }
    return hitTestingBounds;
}


@end
